#ifndef __INNNER_WEAR_FLASH__
#define __INNNER_WEAR_FLASH__
#include "stdint.h"



typedef struct wear_level_flash
{
    uint32_t      page_size;    // 可擦除扇区大小
    uint32_t      entry_size;   // 每隔条目的大小
    uint32_t      st_page;      // 区域起始地址, 这个是固定的
    uint32_t      end_page;     // 最后一个有效扇区
    uint32_t      last_entry;   // 最后一条在扇区的偏移地址
    uint32_t      page_nr;      // 总共用几个扇区

    uint32_t      cur_addr;     // 当前有效条目

    union {
        struct {
            uint32_t       used_count;
            uint32_t       inv_used_count;
            uint32_t       ok_count;
            uint32_t       inv_ok_count;
        } data;
        uint32_t buf[4];
    } u;
} wear_level_flash_t;


/* inner flash */
int inn_flash_eraser_sector(uint32_t addr);
int inn_flash_write_32b(uint32_t address, uint32_t length, uint32_t* data_32);
void inn_flash_read_32b(uint32_t address, uint32_t length, uint32_t* data_32);


int flash_level_reset(wear_level_flash_t *wl);
int flash_level_find_entry(wear_level_flash_t *wl);
int flash_level_write_entry(wear_level_flash_t *wl);
// int flash_level_write_entry(wear_level_flash_t *wl);

#endif
